package trefliq.persistence.entity;

import java.io.Serializable;
import java.sql.Date;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;

/**
 *
 * @author Eric
 */
@Entity
@NamedQuery(name="findAllReviews", query="select r from Review r")
public class Review implements Serializable {
 
    private ReviewPK primarykey;
    
    private String review;
    
    private Date posteddate;
    
    private Boolean approved;
    
    private Integer rating;
    
    public Review() {
    }
    
    public Review(Long movieid, Long accountid) {
        
        primarykey.setMovieid(movieid);
        primarykey.setAccountid(accountid);
    }
    
    public Review(Long movieid, Long accountid, Integer rating) {
        
        primarykey.setMovieid(movieid);
        primarykey.setAccountid(accountid);

        this.rating = rating;
    }
    
    @EmbeddedId
    public ReviewPK getPrimarykey() {
        return primarykey;
    }
    
    public void setPrimarykey(ReviewPK primarykey) {
        this.primarykey = primarykey;
    }

    public String getReview() {
        return review;
    }
    
    public void setReview(String review) {
        this.review = review;
    }
    
    public Date getPosteddate() {
        return posteddate;
    }
    
    public void setPosteddate(Date posteddate) {
        this.posteddate = posteddate;
    }
    
    public Boolean isApproved() {
        return approved;
    }
    
    public void setApproved(Boolean approved) {
        this.approved = approved;
    }
    
    public Integer getRating() {
        return rating;
    }
    
    public void setRating(Integer rating) {
        this.rating = rating;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (primarykey != null ? primarykey.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Review)) {
            return false;
        }
        Review other = (Review) object;
        if ((this.primarykey == null && other.primarykey != null) || (this.primarykey != null && !this.primarykey.equals(other.primarykey))) {
            return false;
        }
        
        return true;
    }

    @Override
    public String toString() {
        return "trefliq.persistence.entity.Review[ primarykey =" + primarykey + " ] rating[" + rating + "]";
    }
}